package com.yang.system.domain.common.validator;

import com.yang.system.adapter.driving.persistence.tenantMng.TenantRepository;
import com.yang.system.domain.common.exception.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CommonValidator {
    private final TenantRepository tenantRepository;

    @Autowired
    public CommonValidator(TenantRepository tenantRepository) {
        this.tenantRepository = tenantRepository;
    }

    //租户必须有效
    public void tenantShouldValid(Long tenantId) {
        if (!tenantRepository.existsById(tenantId)) {
            throw new BusinessException("租户不存在");
        }
    }
}
